package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.CoreEnterpriseEngineerDto;
import com.corechina.apex_osswords.domain.dto.CoreMaintenanceEngineerDto;
import com.corechina.apex_osswords.domain.entity.CoreMaintenanceEngineer;
import com.corechina.apex_osswords.service.ICoreMaintenanceEngineerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 运维人员信息表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-03-11
 */

@Api(tags = "运维人员管理")
@RestController
@RequestMapping("/core/maintenanceEngineer")
public class CoreMaintenanceEngineerController {

    @Autowired
    private ICoreMaintenanceEngineerService iCoreMaintenanceEngineerService;

    @ApiOperation("新增")
    @SysLog("新增运维人员")
    @PostMapping("/add")
    public Response add(@RequestBody CoreMaintenanceEngineerDto coreMaintenanceEngineerDto) {
        coreMaintenanceEngineerDto.setEnterpriseId(ShiroUtils.getEnterpriseId());
        return iCoreMaintenanceEngineerService.add(coreMaintenanceEngineerDto);
    }

    @ApiOperation("编辑")
    @SysLog("编辑运维人员")
    @PutMapping("/update")
    public Response update(@RequestBody CoreMaintenanceEngineer coreMaintenanceEngineer) {
        coreMaintenanceEngineer.setCreateEnterprise(null);
        iCoreMaintenanceEngineerService.updateById(coreMaintenanceEngineer);
        return Response.ok();
    }

    @ApiOperation("删除")
    @SysLog("删除运维人员")
    @DeleteMapping("/del")
    public Response del(Integer id, Integer serviceId) {
        return iCoreMaintenanceEngineerService.delete(id, serviceId);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreMaintenanceEngineerService.getOne(id);
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, String company, String engineerType, Integer serviceId, Integer pageIndex, Integer pageSize) {
        return iCoreMaintenanceEngineerService.getList(name, company, engineerType, serviceId, 0, pageIndex, pageSize);
    }

    @ApiOperation("根据手机号查询运维人员信息")
    @GetMapping("/getByTel")
    public Response getByTel(String tel, Integer serviceId, Integer engineerType) {
        return iCoreMaintenanceEngineerService.getByTel(tel, ShiroUtils.getEnterpriseId(), serviceId, engineerType);
    }

    @ApiOperation("添加企业运维人员")
    @SysLog("添加企业运维人员")
    @PostMapping("/addEnterpriseEngineer")
    public Response addEnterpriseEngineer(@RequestBody CoreEnterpriseEngineerDto coreEnterpriseEngineerDto) {
        return iCoreMaintenanceEngineerService.addEnterpriseEngineer(coreEnterpriseEngineerDto);
    }
}

